import React from 'react'

export default React.createClass({

    propTypes: {
        callback: React.PropTypes.func
    },

    getInitialState: function() {
        return {
            seconds: 60
        };
    },

    countDown: function(){
        this.setState({
            seconds: this.state.seconds - 1
        });
        if(this.state.seconds === 0) this.props.callback();
    },

    isEnd: undefined,

    componentDidMount: function() {
        this.countDown();
        this.isEnd = setInterval(this.countDown, 1000);
    },

    componentWillUnmount: function() {
        if(this.isEnd) clearInterval(this.isEnd);
    },

    render: function(){
        return (
            <div className="count-down">{this.state.seconds}s后重新发送</div>
        );
    },
})
